16. Using the Lidar Object

Using the Lidar Object

ND313 C1 L1 A13 Using The Lidar Object

Lidar Sensing

To go further with your newly created Lidar object, check out src/sensors/lidar.h to see how everything is defined. In this header file, you can see the ray object being defined. Lidar will use these rays to sense its surrounding by doing ray casting. The scan function from the lidar struct will be what is doing the ray casting.

Now let's call the lidar scan function and see how lidar rays look. Back in your environment file, right after the call to the Lidar constructor, you can use the scan function and then render the lidar rays.

Simulated Lidar Rays

Lidar Sensing

Lidar Sensing

Instructions for Using the Lidar Object

Exercise

  • To create a point cloud, call the lidar scan() method on your lidar object.
  • You will store results in a PointCloud pointer object, pcl::PointCloud<pcl::PointXYZ>::Ptr
  • The type of point for the PointCloud will be pcl::PointXYZ .
  • Call the renderRays function with generated PointCloud pointer.

Note

The syntax of PointCloud with the template is similar to the syntax of vectors or other std container libraries: ContainerName<ObjectName> .

The Ptr type from PointCloud indicates that the object is actually a pointer - a 32 bit integer that contains the memory address of your point cloud object. Many functions in pcl use point cloud pointers as arguments, so it's convenient to return the inputCloud in this form.

The renderRays function is defined in src/render . It contains functions that allow us to render points and shapes to the pcl viewer. You will be using it to render your lidar rays as line segments in the viewer.

The arguments for the renderRays function is viewer, which gets passed in by reference. This means that any changes to the viewer in the body of the renderRays function directly affect the viewer outside the function scope. The lidar position also gets passed in, as well as the point cloud that your scan function generated. The type of point for the PointCloud will be pcl::PointXYZ . We will talk about some other different types of point clouds in a bit.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a

Solution

ND313 C1 L1 A14 Using The Lidar Object Solution